package j02jiekou;

import java.util.function.*;

public class J1 {
    public static void main(String[] args) {
        Consumer<Integer> c1 = new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) {
                System.out.println(integer);
            }
        };
        c1.accept(4);

        Consumer<String> c2 = s-> System.out.println(s);
        c2.accept("hello");
        System.out.println("=======");
        Supplier<Double> s1 = ()->Math.random()*10;
        System.out.println("s1 = " + s1);
        System.out.println("s1 = " + s1.get());
        System.out.println("s1 = " + s1.get());
        System.out.println("s1 = " + s1.get());
        System.out.println("==函数行接口==");
        Function<Integer,String> f = sex->sex==1?"男":"女";
        System.out.println(f.apply(1));
        System.out.println(f.apply(2));
        System.out.println(f.apply(0));
        System.out.println("==断言==");
        int score = 34;
        Predicate<Integer> p1 = score1->score1>=60?true:false;
        System.out.println(p1.test(score));//false
        System.out.println(p1.test(60));//true
        System.out.println(p1.test(600));//true
    }
}

class Cat {
    String name;
    int age;

    public Cat(String name, int age) {
        this.name = name;
        this.age = age;

    }

    @Override
    public String toString() {
        return "Cat{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

class J2{
    public static void main(String[] args) {
        BiFunction<String,Integer,Cat> b1 = (name,age)->{
            return new Cat(name,age);
        };

        Cat c1 = b1.apply("波斯猫",2);
        Cat c2 = b1.apply("波斯猫4",4);

        System.out.println("c1 = " + c1);
        System.out.println("c2 = " + c2);
    }
}